﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

#region clsPageBase類別

public class clsPageBase : System.Web.UI.Page
{

    #region Property

    //public string FormID
    //{
    //    get
    //    {
    //        return  this.ViewState["FormID"].ToString();

    //    }
    //    set
    //    {
    //        this.ViewState["FormID"] = value.ToString();
    //    }
    //}

    //public FormViewMode DataAccessMode
    //{
    //    get { return (FormViewMode)this.ViewState["DataAccessMode"]; }
    //    set { this.ViewState["DataAccessMode"] = value; }
    //}

    #endregion

    public DataTable dtCaseReportForm_CarOwner
    {
        get
        {
            return (DataTable)(this.ViewState["dtCaseReportForm_CarOwner"]);

        }
        set
        {
            this.ViewState["dtCaseReportForm_CarOwner"] = value;
        }
    }

    public DataTable dtCaseReportForm_DescDocNotice
    {
        get
        {
            return (DataTable)(this.ViewState["dtCaseReportForm_DescDocNotice"]);

        }
        set
        {
            this.ViewState["dtCaseReportForm_DescDocNotice"] = value;
        }
    }

    public DataTable dtCaseReportForm_DescDoc
    {
        get
        {
            return (DataTable)(this.ViewState["dtCaseReportForm_DescDoc"]);

        }
        set
        {
            this.ViewState["dtCaseReportForm_DescDoc"] = value;
        }
    }

    public DataTable dtActionForm_PetitionDoc
    {
        get
        {
            return (DataTable)(this.ViewState["dtActionForm_PetitionDoc"]);

        }
        set
        {
            this.ViewState["dtActionForm_PetitionDoc"] = value;
        }
    }

    public DataTable dtActionForm_PunishDoc
    {
        get
        {
            return (DataTable)(this.ViewState["dtActionForm_PunishDoc"]);
        }
        set
        {
            this.ViewState["dtActionForm_PunishDoc"] = value;
        }
    }

    public DataTable dtActionForm_TribDoc
    {
        get
        {
            return (DataTable)(this.ViewState["dtActionForm_TribDoc"]);
        }
        set
        {
            this.ViewState["dtActionForm_TribDoc"] = value;
        }
    }

    public DataTable dtReleaseForm_Pay
    {
        get
        {
            return (DataTable)(this.ViewState["dtReleaseForm_Pay"]);
        }
        set
        {
            this.ViewState["dtReleaseForm_Pay"] = value;
        }
    }   
    

}
#endregion


#region clsUCBase類別

public class clsUCBase : System.Web.UI.UserControl
{

    public string FormID
    {
        get
        {
            return this.ViewState["FormID"].ToString();

        }
        set
        {
            this.ViewState["FormID"] = value;
        }
    }

    public int FormStatus
    {
        get
        {
            return (int)this.ViewState["FormStatus"];

        }
        set
        {
            this.ViewState["FormStatus"] = value;
        }
    }

    public FormViewMode DataAccessMode
    {
        get { return (FormViewMode)this.ViewState["DataAccessMode"]; }
        set { this.ViewState["DataAccessMode"] = value; }
    }

    protected virtual void Page_Init(object sender, System.EventArgs e)
    {
        System.Web.UI.WebControls.FormView theFormView = (System.Web.UI.WebControls.FormView)this.FindControl("FormView_Master");
        if (theFormView != null)
        {
            theFormView.InsertItemTemplate = theFormView.ItemTemplate;
            theFormView.EditItemTemplate = theFormView.ItemTemplate;
        }
    }

    protected virtual void Page_Load(object sender, System.EventArgs e)
    {

        System.Web.UI.WebControls.FormView theFormView = (System.Web.UI.WebControls.FormView)this.FindControl("FormView_Master");

        if (this.DataAccessMode == FormViewMode.Insert)
        {
            if (theFormView != null)
            {
                theFormView.ChangeMode(System.Web.UI.WebControls.FormViewMode.Insert);
            }

            //DrawSelectedPanel();
        }
        else if (this.DataAccessMode == FormViewMode.Edit)
        {
            //theFormView.ItemTemplate = null;
            //theFormView.InsertItemTemplate = null;

            if (theFormView != null)
            {
                theFormView.ChangeMode(System.Web.UI.WebControls.FormViewMode.Edit);
            }

            //DrawSelectedPanel();
        }
        else if (this.DataAccessMode == FormViewMode.ReadOnly)
        {
            if (theFormView != null)
            {
                theFormView.ChangeMode(System.Web.UI.WebControls.FormViewMode.Edit);
            }
        }


    }

    protected virtual void Page_PreRender(object sender, System.EventArgs e)
    {
        if (this.DataAccessMode == FormViewMode.ReadOnly)
        {
            EnableSubControls(this, false, string.Empty);
        }
    }

    //public void DrawSelectedPanel()
    //{
    //    //可編輯的UserControl
    //    Panel pnlSelected = (Panel)this.FindControl("pnlSelected");
    //    pnlSelected.BorderColor = System.Drawing.Color.Red;
    //    pnlSelected.BorderStyle = BorderStyle.Dashed;
    //    pnlSelected.BorderWidth = Unit.Pixel(2);
    //    pnlSelected.Width = Unit.Percentage(100);

    //}

    #region EnableSubControls-Enable某控件內的子控件

    public static void EnableSubControls(System.Web.UI.Control MainObject, Boolean bolEnable, string strExceptControls)
    {
        ArrayList arrlEnableControls = new ArrayList();
        arrlEnableControls.AddRange("TextBox,DropDownList,CheckBox,TDropDownList,TCheckBoxList,TRadioButtonList,CheckBoxList,RadioButton,RadioButtonList,DataPicker,Button,RequiredFieldValidator,CompareValidator,FileUpload,LinkButton".Split(','));

        ArrayList arrlExceptControl = new ArrayList();
        arrlExceptControl.AddRange(strExceptControls.Split(','));

        foreach (System.Web.UI.Control objSubControl in MainObject.Controls)
        {

            if (objSubControl is System.Web.UI.WebControls.WebControl)
            {

                if (arrlEnableControls.Contains(objSubControl.GetType().Name) && !arrlExceptControl.Contains(objSubControl.GetType().Name))
                {
                    if (objSubControl.GetType().Name.Equals("TextBox") && ((System.Web.UI.WebControls.TextBox)objSubControl).TextMode == TextBoxMode.MultiLine)
                    {
                        ((System.Web.UI.WebControls.TextBox)objSubControl).ReadOnly = !bolEnable;
                    }
                    else
                    {
                        ((System.Web.UI.WebControls.WebControl)objSubControl).Enabled = bolEnable;
                    }

                }

            }

            EnableSubControls(objSubControl, bolEnable, strExceptControls);

        }
    }

    #endregion


}



#endregion
